package com.medusa.aps.business.modules.board.model.bo;

import cn.hutool.core.collection.CollUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.time.Duration;
import java.util.Set;

/**
 * @author 张治保
 * @since 2024/1/6
 */
@Getter
@Setter
@ToString
@Accessors(chain = true)
public class DeviceTask {

    /**
     * 设备名称
     */
    private String deviceName;

    /**
     * 车间名称
     */
    private String workshopName;

    /**
     * 关联订单号
     */
    private Set<String> orders = CollUtil.newHashSet();

    /**
     * 计划数
     */
    private Integer plans = 0;

    /**
     * 完成数
     */
    private Integer completes = 0;

    /**
     * 当日已安排的工作时间
     */
    private Duration worked = Duration.ZERO;

    /**
     * 当日总的可工作时间
     */
    private Duration workable = Duration.ZERO;


    public DeviceTask addOrder(String orderNumber) {
        this.orders.add(orderNumber);
        return this;
    }


    public DeviceTask add(DeviceTask task) {
        this.deviceName = task.deviceName;
        this.workshopName = task.workshopName;
        this.orders.addAll(task.orders);
        this.plans += task.plans;
        this.completes += task.completes;
        this.worked = this.worked.plus(task.worked);
        this.workable = this.workable.compareTo(task.workable) > 0 ? this.workable : task.workable;
        return this;
    }

}
